home *** CD-ROM | disk | FTP | other *** search
- TITLE: MASM source for ENV.COM
- This is the MASM source to create ENV.COM. The following commands are
- used to do it...
- MASM env;
- LINK env;
- EXE2BIN env.exe env.com
-
- Source follows...
- -------------
- PAGE 64,132
- TITLE ENV 5-30-86 [5-30-86]
- ;
- .RADIX 16
- CSEG SEGMENT PARA PUBLIC 'CODE'
- ASSUME DS:CSEG, SS:CSEG ,CS:CSEG ,ES:CSEG
- ORG 0100
- START: MOV SI,80 ;print the command line
- LODSB ;parameters
- AND AX,7F ;
- JZ L0117 ;
- MOV DI,AX ;
- ADD DI,SI ;
- MOV BYTE PTR [DI],24 ;
- MOV DX,SI ;
- INC DX ;
- MOV AH,9 ;
- INT 21 ;
- L0117: MOV DX,OFFSET INPUT ;accept input into buffer
- MOV AH,0A ;
- INT 21 ;
- CALL L01A0 ;this finds the environment!
- MOV CX,BX ;count
- MOV ES,AX ;segment of target
- XOR DI,DI ;offset of target
- XOR AL,AL ;looking for NUL
- CLD ;scan forward
- L012A: REPNZ SCASB ;do scan
- JNZ L016C ;not found -> exit with error
- CMP AL,ES:[DI] ;next byte NUL also? (end of
- JZ L0171 ;environment) yes...
- MOV DX,DI ;no... save offset
- MOV BP,CX ;save count
- MOV SI,OFFSET RESULT ;compare against...
- MOV CX,7 ;comparing first 7 bytes
- REPZ CMPSB ;compare
- JZ L0147 ;is it equal? yes...
- MOV DI,DX ;restore offset
- MOV CX,BP ;restore count
- JMP SHORT L012A ;...and scan again
- L0147: MOV CX,51
- REPNZ SCASB
- JNZ L016C
- MOV SI,DI
- MOV DI,DX
- MOV CX,ES
- MOV DS,CX
- MOV CX,BX
- SUB CX,SI
- L015A: LODSB
- AND AL,AL
- JZ L0171
- L015F: STOSB
- LOOP L0164
- JMP SHORT L016C
- L0164: LODSB
- AND AL,AL
- JNZ L015F
- STOSB
- LOOP L015A
- L016C: MOV AX,4C01 ;exit with error
- INT 21 ;
- L0171: MOV BYTE PTR ES:[DI],0
- MOV AX,CS
- MOV DS,AX
- MOV AL,LENGTH
- XOR AH,AH
- ADD AX,8
- ADD AX,DI
- CMP AX,BX
- JNB L016C
- MOV SI,OFFSET RESULT
- MOV CX,7
- REPZ MOVSB
- MOV SI,OFFSET TEXT
- MOV CL,LENGTH
- REPZ MOVSB
- XOR AX,AX
- STOSW
- MOV AX,4C00 ;exit without error
- INT 21 ;
-
- ;somehow, this proc finds the environment of the process that performs the
- ; DOS critical error handler - this is the segment where the answer will
- ; be placed (AX has the segment, BX has (some) length...) (but I don't
- ; know how it does it...)
- L01A0 PROC NEAR
- PUSH ES ;save es
- MOV AX,CS ;cs into es
- MOV ES,AX ;
- MOV AX,ES:14 ;critical error exit segment
- MOV ES,AX ;into es
- MOV AX,ES:2C ;environment segment of the
- ;process doing the critical
- ;error handler!
- AND AX,AX ;is it zero?
- JNZ L01C0 ;yes...
- MOV AX,ES ;this loads ax with the word
- DEC AX ;at offset 3 into the
- MOV ES,AX ;segment before the PSP of
- ADD AX,ES:3 ;the critical error handler
- ADD AX,2 ;add two
- L01C0: DEC AX ;subtract one
- MOV ES,AX ;load bx with the number of
- INC AX ;paragraphs within the
- MOV BX,ES:3 ;environment segment
- SHL BX,1 ;multiply by 10h
- SHL BX,1 ;
- SHL BX,1 ;
- SHL BX,1 ;
- POP ES ;restore es
- RET ;and return
- L01A0 ENDP
-
- INPUT DB 50 ;length of buffer
- LENGTH DB 00 ;spot for characters read
- TEXT DB 50 DUP(00) ;the buffer
- RESULT: DB 'ANSWER=VER 1.00' ;the default environ string
- CSEG ENDS
-
- END START